<%@ include file="/WEB-INF/template/include.jsp"%>

<openmrs:require privilege="Manage Summaries" otherwise="/login.htm" redirect="/module/clinicalsummary/summaryDownload.form" />

<%@ include file="/WEB-INF/template/header.jsp"%>
<%@ include file="localHeader.jsp" %>

<openmrs:htmlInclude file="/scripts/calendar/calendar.js" />
<openmrs:htmlInclude file="/dwr/interface/DWRSummaryService.js"/>
<openmrs:htmlInclude file="/dwr/engine.js"/>
<openmrs:htmlInclude file="/dwr/util.js"/>
<openmrs:htmlInclude file="/moduleResources/clinicalsummary/scripts/jquery/jquery-1.4.2.min.js" />
<openmrs:htmlInclude file="/moduleResources/clinicalsummary/scripts/jquery-ui/js/jquery-ui-1.8.2.custom.min.js" />
<openmrs:htmlInclude file="/moduleResources/clinicalsummary/scripts/jquery-ui/css/redmond/jquery-ui-1.8.2.custom.css" />

<script type="text/javascript" charset="utf-8">

$j = jQuery.noConflict();

$j(document).ready(function() {

	// add hover state change
	$j(':input:not(.ui-state-disabled)').hover(
		function(){
			$j(this).addClass('ui-state-hover');
		},
		function(){
			$j(this).removeClass('ui-state-hover');
		}
	)
	
	// init all input to use jquery css
	$j(':input').addClass('ui-state-default ui-corner-all');
	
});

function refreshSecretFile() {
	setTimeout("buildTable()", 2000);
}

function buildTable() {
	DWRSummaryService.getAllSecretFiles(function writeBlockingRuns(block) {
        DWRUtil.removeAllRows("secretFileSection");
        
        var cellFuncs = [
            function(data) {
                return "<a href=\"${pageContext.request.contextPath}/moduleServlet/clinicalsummary/secret?secretFile=" + data + "\" onClick=\"refreshSecretFile()\" >" + data + "</a>";
            }
        ];
        
        DWRUtil.addRows( "secretFileSection", block, cellFuncs, {
            rowCreator:function(options) {
                var row = document.createElement("tr");
                var index = options.rowIndex;
                if (index % 2)
                    row.className = "oddRow";
                else
                    row.className = "evenRow";
                return row;
            },
            cellCreator:function(options) {
                var td = document.createElement("td");
                return td;
            },
            escapeHtml:false
        });
    });
}

</script>

<style>

.smallBox {
	width: 80%;
	margin-left:0px;
	padding: 5px;
}

.sparseTable {
	padding: 5px;
	spacing: 5px;
}

</style>

<h2><spring:message code="clinicalsummary.title" /></h2>

<spring:message code="clinicalsummary.downloadInstructions"/>

<form method="post" enctype="multipart/form-data" action="">
	<b class="boxHeader smallBox"><spring:message code="clinicalsummary.downloadHeader" /></b>
	<div class="box smallBox">
	<table class="sparseTable">
		<tr>
			<td><spring:message code="clinicalsummary.password"/></td>
			<td>
				<input type="password" name="password" />
			</td>
		</tr>
		<tr>
			<td><spring:message code="clinicalsummary.passphrase"/></td>
			<td>
				<input type="password" name="passphrase" />
			</td>
		</tr>
		
	</table>
	
	<input type="submit" value="<spring:message code="clinicalsummary.downloadCollection"/>" onClick="refreshSecretFile();" />
	</div>
</form>
<br /> <br />
	<b class="boxHeader smallBox"><spring:message code="clinicalsummary.secretFile" /></b>
	<div class="box smallBox">
		<table class="sparseTable">
			<tbody id="secretFileSection">
				<c:forEach items="${secretFiles}" var="secretFile">
					<tr>
						<td>
							<a href="${pageContext.request.contextPath}/moduleServlet/clinicalsummary/secret?secretFile=${secretFile}" onClick="refreshSecretFile();" >${secretFile}</a>
						</td>
					</tr>
				</c:forEach>
			</tbody>
		</table>
	</div>

<%@ include file="/WEB-INF/template/footer.jsp"%>